#!/bin/bash

 jknc(){
      total=`free -m |grep Mem |tr -s " "|cut -d " " -f2`
      used=`free -m |grep Mem |tr -s " "|cut -d " " -f3`
      result=`echo "scale=3;$used/$total>0.8" |bc`
      if ($result == 1) &>/dev/null
      then
          echo "内存使用率已大于80%!!!"
      else
          echo "内存使用率小于80%"
      fi
 }

scan_ip(){
     for ip in 192.168.0.`seq 255`
     do
         (ping -c 1 $ip &>/dev/null && echo $ip >>up.txt ||echo $ip >> down.txt) &
     done
 wait
 }
 
jkwjxg(){
    a=`diff /etc/passwd /lianxi/passwd |wc -l`
    [[ a -eq 0 ]] && echo "文件未被修改" ||echo "文件已被修改"
}

cxnginx(){
    pidof nginx && echo "nginx进程已启动" ||echo "nginx进程未启动"
}


    echo "请选择你想要使用的功能:"
    echo "1.监控内存使用情况,如果内存使用率大于百分之80，给予提醒"
    echo "2.扫描局域网ip,检查哪些ip地址正在使用"
    echo "3.监控文件/etc/passwd是否被修改"
    echo "4.监控nginx进程是否存在，不存在就给予相应提醒"
    echo "5.退出"

while :
do     
    read -p "请输入你的选择:" options   
    case $options in

    1)
        jknc
        continue
        ;;

    2)
        scan_ip
        continue
        ;;

    3)
        jkwjxg
        continue
        ;;

    4)
        cxhginx
        continue
        ;;
    5)
        echo "退出"
        exit
        ;;
    esac
done


